<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>查找字符串首次出现的位置（不区分大小写）</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stripcslashes.html">stripcslashes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stripslashes.html">stripslashes</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.stripos" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stripos</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">stripos</span> &mdash; <span class="dc-title">查找字符串首次出现的位置（不区分大小写）</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.stripos-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>stripos</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$haystack</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$needle</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   返回在<span class="type"><span class="type 字符串">字符串</span></span> <em><code class="parameter">haystack</code></em> 中 <em><code class="parameter">needle</code></em> 首次出现的数字位置。
  </p>
  <p class="para">
   与 <span class="function"><a href="function.strpos.html" class="function">strpos()</a></span> 不同，<span class="function"><strong>stripos()</strong></span> 不区分大小写。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stripos-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">haystack</code></em></dt>

     <dd>

      <p class="para">
       在该字符串中查找。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">needle</code></em></dt>

     <dd>

      <p class="para">
       注意 <em><code class="parameter">needle</code></em> 可以是一个单字符或者多字符的字符串。
      </p>
      <p class="para">
       如果 <em><code class="parameter">needle</code></em> 不是一个字符串，那么它将被转换为整型并被视为字符顺序值。
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">offset</code></em></dt>

     <dd>

      <p class="para">
       可选的 <em><code class="parameter">offset</code></em> 参数允许你指定从 <em><code class="parameter">haystack</code></em> 中的哪个字符开始查找。返回的位置数字值仍然相对于 <em><code class="parameter">haystack</code></em> 的起始位置。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stripos-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果未发现 <em><code class="parameter">needle</code></em>，<span class="function"><strong>stripos()</strong></span> 将返回<span class="type"><span class="type 布尔型">布尔型</span></span> <strong><code>FALSE</code></strong>。
  </p>
  <div class="warning"><strong class="warning">Warning</strong><p class="simpara">此函数可能返回布尔值
<strong><code>FALSE</code></strong>，但也可能返回等同于 <strong><code>FALSE</code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.html" class="link">布尔类型</a>章节以获取更多信息。应使用
<a href="language.operators.comparison.html" class="link">===
运算符</a>来测试此函数的返回值。</p></div>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stripos-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4789">
   <p><strong>Example #1 <span class="function"><strong>stripos()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$findme&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'a'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xyz'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$mystring2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'ABC'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pos1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pos2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stripos</span><span style="color: #007700">(</span><span style="color: #0000BB">$mystring2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$findme</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;'a'&nbsp;当然不在&nbsp;'xyz'&nbsp;中<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$pos1&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;string&nbsp;'</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">'&nbsp;was&nbsp;not&nbsp;found&nbsp;in&nbsp;the&nbsp;string&nbsp;'</span><span style="color: #0000BB">$mystring1</span><span style="color: #DD0000">'"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;注意这里使用的是&nbsp;===。简单的&nbsp;==&nbsp;不能像我们期望的那样工作，<br />//&nbsp;因为&nbsp;'a'&nbsp;的位置是&nbsp;0（第一个字符）。<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$pos2&nbsp;</span><span style="color: #007700">!==&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"We&nbsp;found&nbsp;'</span><span style="color: #0000BB">$findme</span><span style="color: #DD0000">'&nbsp;in&nbsp;'</span><span style="color: #0000BB">$mystring2</span><span style="color: #DD0000">'&nbsp;at&nbsp;position&nbsp;</span><span style="color: #0000BB">$pos2</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stripos-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stripos-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strpos.html" class="function" rel="rdfs-seeAlso">strpos()</a> - 查找字符串首次出现的位置</span></li>
    <li class="member"><span class="function"><a href="function.strrpos.html" class="function" rel="rdfs-seeAlso">strrpos()</a> - 计算指定字符串在目标字符串中最后一次出现的位置</span></li>
    <li class="member"><span class="function"><a href="function.strrchr.html" class="function" rel="rdfs-seeAlso">strrchr()</a> - 查找指定字符在字符串中的最后一次出现</span></li>
    <li class="member"><span class="function"><a href="function.substr.html" class="function" rel="rdfs-seeAlso">substr()</a> - 返回字符串的子串</span></li>
    <li class="member"><span class="function"><a href="function.stristr.html" class="function" rel="rdfs-seeAlso">stristr()</a> - strstr 函数的忽略大小写版本</span></li>
    <li class="member"><span class="function"><a href="function.strstr.html" class="function" rel="rdfs-seeAlso">strstr()</a> - 查找字符串的首次出现</span></li>
    <li class="member"><span class="function"><a href="function.strripos.html" class="function" rel="rdfs-seeAlso">strripos()</a> - 计算指定字符串在目标字符串中最后一次出现的位置（不区分大小写）</span></li>
    <li class="member"><span class="function"><a href="function.str-ireplace.html" class="function" rel="rdfs-seeAlso">str_ireplace()</a> - str_replace 的忽略大小写版本</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.stripcslashes.html">stripcslashes</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.stripslashes.html">stripslashes</a></div>
 <div class="up"><a href="ref.strings.html">字符串函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
